<?php
require_once('includes/common.php');
pr($_FILES);
if($_FILES['avatar']['size'] >= 500*1024) {
  $_SESSION['msg'] = ('<span class="errMsg">Image size shuld not exceed 2MB</span>');
  header('location:registration.php');
}
/// Process to upload file///
$source = $_FILES['avatar']['tmp_name'];

$fileName = date('YmdHis').'_'.$_FILES['avatar']['name'];

$dest = "uploads/$fileName";
copy($source, $dest);
//// Pre process to handle submitted values////////
unset($_POST['conPassword']);
$_POST['lang'] = implode(',',$_POST['lang']);
$_POST['hobbies'] = implode(',',$_POST['hobbies']);
$_POST['added_date'] = date('Y-m-d H:i:s');
$_POST['avatar'] = $fileName;
$_POST['password'] = md5($_POST['password']);
//// FROM NOW $_POST is as we want////////
//pr($_POST);

$insertQuery = "INSERT INTO `users` SET ";
foreach($_POST as $colName=>$value) {
  $insertQuery .="`$colName`='$value',";
}
$insertQuery = trim($insertQuery,', ');
echo $insertQuery;

$result = mysql_query($insertQuery) or die(mysql_error());

// to check how many records we inserted
pr( mysql_affected_rows());

// to get last inserted ID
pr( mysql_insert_id());






